/* @file SHGetInfo.Java Display Get Info Dialog
 * @author Jay Schulist jjschlst@gmail.com
 * 
 * Copyright (C) 2007 Jay Schulist
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package stickyhand.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.Box;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.TitledBorder;

import stickyhand.NZB;

public class SHGetInfo extends JDialog {
	NZB nzb_info = null;
	JTabbedPane tp = null;
	JPanel infoP, actP, errP;

	SHGetInfoFile fileP;
	
	private JPanel createInfo() {
		JPanel in = new JPanel();
		in.setBorder(new TitledBorder(nzb_info.getName()));
		in.setLayout(new BorderLayout());
		
		JPanel in_w = new JPanel();
		in_w.setLayout(new BorderLayout());
		in_w.add(new JLabel("Size:     " + SHJList.formatBytes(nzb_info.getBytes())), BorderLayout.NORTH);
		in_w.add(new JLabel("Files:    " + nzb_info.getNumFiles()), BorderLayout.CENTER);
		in_w.add(new JLabel("Segments: " + nzb_info.getNumSegments()), BorderLayout.SOUTH);
		in.add(in_w, BorderLayout.WEST);
		
		JPanel in_c = new JPanel();
		in_c.setLayout(new BorderLayout());
		in_c.add(new JLabel("Status: " + "ready..."), BorderLayout.NORTH);
		in.add(in_c, BorderLayout.CENTER);
		return in;
	}
	
	public SHGetInfo(JFrame owner, NZB nzb_info) {
		super(owner, nzb_info.getName() + " Info");
		
		Dimension winSize = new Dimension(600, 400);
		
		this.nzb_info = nzb_info;
		setLayout(new BorderLayout());
		setPreferredSize(winSize);
		add(Box.createVerticalStrut(15), BorderLayout.SOUTH);
		
		tp = new JTabbedPane(JTabbedPane.TOP);
		fileP = new SHGetInfoFile(nzb_info);
		fileP.updateSize(winSize);
		tp.add(fileP);
		
		actP = new JPanel();
		actP.setName("Activity");
		tp.add(actP);
		
		errP = new JPanel();
		errP.setName("Errors");
		tp.add(errP);
		
		add(tp, BorderLayout.CENTER);
		
		infoP = createInfo();
		add(infoP, BorderLayout.NORTH);
		
		addComponentListener(new ComponentListener() {
			public void componentResized(ComponentEvent evt) {
				Component c = (Component)evt.getSource();
				Dimension newSize = c.getSize();
				fileP.updateSize(newSize);
			}

			public void componentHidden(ComponentEvent arg0) {
				// TODO Auto-generated method stub

			}

			public void componentMoved(ComponentEvent arg0) {
				// TODO Auto-generated method stub

			}

			public void componentShown(ComponentEvent arg0) {
				// TODO Auto-generated method stub

			}
		});
		
		pack();
		setVisible(true);
	}
}
